package com.shycloud.mido.common.sms.service;

import com.shycloud.mido.common.sms.sdk.CloopenSmsSDK;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * CloopenSmsService 交互类
 *
 * @author nianhua.jiang
 */
@RequiredArgsConstructor
public class CloopenSmsService implements InitializingBean {

	/** 发送验证码模板编号 */
	private static final String MODEL_VCODE = "642843";
	/** 时间参数(五分钟) */
	private static final String ONE_MINUTE = "5分钟";

	@Autowired
	private CloopenSmsSDK cloopenSmsSDK;

	/**
	 * 创建bucket
	 *
	 * @param mobile 手机号码
	 * @param code   验证码
	 */
	@SneakyThrows
	public String sendVerificationCode(String mobile, String code) {
		return this.cloopenSmsSDK.sendTemplateSMS(mobile, MODEL_VCODE, new String[]{code, ONE_MINUTE}).get("statusCode").toString();
	}

	@Override
	public void afterPropertiesSet() throws Exception {

	}
}
